package com.vint.leetcode;

import com.vint.common.TreeNode;
import sun.reflect.generics.tree.Tree;

import java.util.ArrayList;
import java.util.List;

/*
 */
public class Leetcode114 {
	public void flatten(TreeNode root) {
		flat(root);
	}

	public TreeNode flat(TreeNode root) {
		if(root==null) return root;
		TreeNode left = root.left;
		root.left = null;
		TreeNode right = root.right;
		root.right = flat(left);
		TreeNode pre = root;
		TreeNode in = root.right;
		while(in!= null) {
			pre = in;
			in = in.right;
		}
		pre.right = flat(right);
		return root;
	}
}
